package cn.swing.his.hospitalization.webapi.controller;

import cn.swing.his.common.web.JsonPage;
import cn.swing.his.common.web.JsonResult;
import cn.swing.his.hospitalization.service.IOhospitalizationService;
import cn.swing.his.pojo.hospitalization.dto.HospitalBedsDTO;
import cn.swing.his.pojo.hospitalization.dto.HospitalBedsDetailsDTO;
import cn.swing.his.pojo.hospitalization.vo.BedByPatientVO;
import cn.swing.his.pojo.hospitalization.vo.HospitalBedsVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chenqi
 */
@Slf4j
@RestController
@RequestMapping(value = "/hospitalization" , produces = "application/json;charset=utf-8")
@Api(tags = "住院部操作模块")
public class HospitalizationController {

    @Autowired
    IOhospitalizationService iohospitalizationService;

    // ===================增
    @ApiOperation("插入病床信息")
    @PostMapping("/insertHospitalBeds")
    public JsonResult<Integer> insertHospitalBeds(HospitalBedsDetailsDTO hospitalBedsDetailsDTO){
        Integer result = iohospitalizationService.insertHospitalBeds(hospitalBedsDetailsDTO);
        return JsonResult.ok("插入成功",result);
    }

    // ===================删
    @ApiOperation("删除床位信息")
    @PostMapping("/deleteHospitalBedsById")
    public JsonResult<Integer> deleteHospitalBedsById(Integer id){
        Integer result = iohospitalizationService.deleteHospitalBedsById(id);
        return JsonResult.ok("删除成功",result);
    }

    @ApiOperation("根据患者id删除床位信息")
    @PostMapping("/deleteHospitalBedsByPatientId")
    public JsonResult<Integer> deleteHospitalBedsByPatientId(Integer patientId){
        Integer result = iohospitalizationService.deleteHospitalBedsById(patientId);
        return JsonResult.ok("删除成功",result);
    }

    // ===================查
    // 查询床位信息
    @ApiOperation("根据id查询床位信息")
    @PostMapping("/hospitalBedList")
    public JsonPage<HospitalBedsVO> getHospitalBeds(int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<HospitalBedsVO> list = iohospitalizationService.getAllHospitalBeds();
        return JsonPage.restPage(new PageInfo<>(list));
    }

    @ApiOperation("根据病房号查询病床信息")
    @PostMapping("/getHospitalBedsByWard")
    public JsonResult<List<HospitalBedsVO>> getHospitalBedsByWard(Integer wardId){
        List<HospitalBedsVO> list = iohospitalizationService.getHospitalBedsByWard(wardId);
        return JsonResult.ok("获取成功",list);
    }

    @ApiOperation("根据病床状态查询病床信息")
    @PostMapping("/getHospitalBedsByState")
    public JsonResult<List<HospitalBedsVO>> getHospitalBedsByState(Integer state){
        List<HospitalBedsVO> list = iohospitalizationService.getHospitalBedsByState(state);
        return JsonResult.ok("获取成功",list);
    }

    @ApiOperation("根据患者ID查询病床信息")
    @PostMapping("/getHospitalBedsByPatientId")
    public JsonResult<BedByPatientVO> getHospitalBedsByPatientId(Integer patientId){
        BedByPatientVO list = iohospitalizationService.getHospitalBedsByPatientId(patientId);
        return JsonResult.ok("获取成功",list);
    }

}
